package com.example.web;

import calculator.web.HomePage;
import org.apache.wicket.Request;
import org.apache.wicket.RequestCycle;
import org.apache.wicket.Response;
import org.apache.wicket.guice.GuiceComponentInjector;
import org.apache.wicket.protocol.http.HttpSessionStore;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.session.ISessionStore;
import org.apache.wicket.util.time.Duration;

/**
 * Application object for your web application.
 */
public class SampleApplication extends WebApplication {
    public Class<HomePage> getHomePage() {
        return HomePage.class;
    }

    StaticModificationWatcher staticModificationWatcher;

    @Override
    protected void init() {
        super.init();

        // for Google App Engine
        getResourceSettings().setResourcePollFrequency(null);
//
//                        staticModificationWatcher = new StaticModificationWatcher();
//                        getResourceSettings().setResourceWatcher(staticModificationWatcher);
//                        getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
//                        getResourceSettings().setAddLastModifiedTimeToResourceReferenceUrl(true);
//        getResourceSettings().addResourceFolder("D:/__krasa/wicket-gae-compound-effect-calculator/src/main/java/calculator/web");
//



    //   iam trying to update markup on gae every request

        // Enable Guice for field injection on Wicket pages.  Unfortunately, constructor injection into
        // pages is not supported.  Supplying ServletModule is optional; it enables usage of @RequestScoped and
        // @SessionScoped, which may not be useful for Wicket applications because the WebPage instances are
        // already stored in session, with their dependencies injected once per session.
        addComponentInstantiationListener(new GuiceComponentInjector(this, new GuiceModule()));
//        addComponentInstantiationListener(new GuiceComponentInjector(this, new ServletModule(), new GuiceModule()));
    }

    @Override
    protected ISessionStore newSessionStore() {
        // for Google App Engine
        return new HttpSessionStore(this);
    }


//    @Override
//    public RequestCycle newRequestCycle
//            (Request
//                    request, Response
//                    response) {
//// In deploymentmode we are not using the staticModificationWatcher
//        if (staticModificationWatcher != null) {
//            staticModificationWatcher.RunCheck();           System.err.println("sssss");
//
//        }
//        return super.newRequestCycle(request, response);
//    }
}
